<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>xmake从入门到精通4：常用C/C++项目描述设置详解</title>
    <meta name="description" content="xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具，主要特点是：语法简单易上手，提供更加可读的项目维护，实现跨平台行为一致的构建体验。本文主要详细讲解如何编写一些常用的基础xmake.lua描述配置，来实现一些简单的C/C++项目构建管理。对于大部分小项目，这些配置已经完全足够使用，本系列后期进阶教...">

    
    <meta name="keywords" content="xmake,lua,c/c++,xmake配置描述,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2019/11/10/quickstart-4-basic-project-settings/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>xmake从入门到精通4：常用C/C++项目描述设置详解</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2019-11-10
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#c%2Fc%2B%2B" title="Tag: c/c++" rel="tag">c/c++</a-->
        <a href="/cn/tag/#c/c++" title="Tag: c/c++" rel="tag">c/c++</a>&nbsp;
    
        <!--a href="/tag/#xmake%E9%85%8D%E7%BD%AE%E6%8F%8F%E8%BF%B0" title="Tag: xmake配置描述" rel="tag">xmake配置描述</a-->
        <a href="/cn/tag/#xmake配置描述" title="Tag: xmake配置描述" rel="tag">xmake配置描述</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <p>xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具，主要特点是：语法简单易上手，提供更加可读的项目维护，实现跨平台行为一致的构建体验。</p>

<p>本文主要详细讲解如何编写一些常用的基础xmake.lua描述配置，来实现一些简单的C/C++项目构建管理。
对于大部分小项目，这些配置已经完全足够使用，本系列后期进阶教程中，我会深入详细讲解如果使用一些高级特性来更加灵活定制化地配置项目。</p>

<ul>
  <li><a href="https://github.com/xmake-io/xmake">项目源码</a></li>
  <li><a href="https://xmake.io/#/zh-cn/">官方文档</a></li>
</ul>

<h3 id="先来一段最简短的">先来一段最简短的</h3>

<p>一行描述即可编译src目录下所有c源文件，然后生成一个名为demo的可执行文件。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">,</span> <span class="p">{</span><span class="n">kind</span> <span class="o">=</span> <span class="s2">"binary"</span><span class="p">,</span> <span class="n">files</span> <span class="o">=</span> <span class="s2">"src/*.c"</span><span class="p">})</span>
</code></pre>
</div>

<p>上面的写法是精简写法，通常我们更推荐使用下面展开式写法：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>这两者完全等价，如果配置很简短，可以完全精简成一行，而拆分成多行更加方便灵活配置。</p>

<p>如果没有特殊目的，下文我们都会采用第二段的写法。</p>

<h3 id="配置项目目标类型">配置项目目标类型</h3>

<p>通常的C/C++项目生成的目标文件主要有三大类：可执行程序，静态库，动态库。</p>

<p>我们可以通过<code class="highlighter-rouge">set_kind()</code>配置来设置，分别对应：binary, static, shared</p>

<p>例如，我们想要编译动态库，只需要修改kind：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="添加宏定义">添加宏定义</h3>

<p>编译宏的设置，大多数c/c++项目都会用到，一般如果我们设置编译flags传给gcc/clang，都是要配置：<code class="highlighter-rouge">-DXXX</code></p>

<p>而在xmake里面，提供了<code class="highlighter-rouge">add_defines()</code>内置接口来配置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"XXX"</span><span class="p">)</span>
</code></pre>
</div>

<h3 id="条件配置">条件配置</h3>

<p>那如果我们想在不同编译平台，分别设置不同的宏开关呢？我们可以利用lua内置的if语句很方便的实现：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"demo"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"XXX"</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"linux"</span><span class="p">,</span> <span class="s2">"macosx"</span><span class="p">)</span> <span class="k">then</span>
        <span class="n">add_defines</span><span class="p">(</span><span class="s2">"YYY"</span><span class="p">)</span>
    <span class="k">end</span>
</code></pre>
</div>

<p>我们通过<code class="highlighter-rouge">is_plat()</code>判断，如果当前编译目标平台是linux或者macosx，那么target会额外增加<code class="highlighter-rouge">-DYYY</code>宏定义。</p>

<h3 id="全局配置">全局配置</h3>

<p>我们在<code class="highlighter-rouge">target("demo")</code>下面的所有配置，都属于demo这个target子域，并不是全局的，所以你会看到通常配置上都加了缩进，就是为了凸显作用域的影响范围。</p>

<p>通常如果多个target连续定义，下一个target定义就会自动结束上个target的作用域，每个target的配置完全独立，互不干扰：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST1"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test2"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST2"</span><span class="p">)</span>
</code></pre>
</div>

<p>例如，上面的配置两个target，各自拥有自己独立的宏定义：<code class="highlighter-rouge">TEST1</code>和<code class="highlighter-rouge">TEST2</code>。</p>

<p>那么，我们要对这两个target，设置共用的宏定义，应该如何配置呢？</p>

<p>每个target下面都配置一遍<code class="highlighter-rouge">add_defines("TEST")</code>? 当然可以，不过这样就有点冗余了，配置多了就会很难维护，其实我们只需要放置到全局根作用域就行了：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- 全局设置</span>
<span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">is_arch</span><span class="p">(</span><span class="s2">"arm64"</span><span class="p">,</span> <span class="s2">"armv7"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"ARM"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST1"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test2"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST2"</span><span class="p">)</span>
</code></pre>
</div>

<p>在target的外层的所有配置都属于全局配置，我们也可以调用<code class="highlighter-rouge">target_end()</code>强制结束target子域，切回全局作用域：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test1"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST1"</span><span class="p">)</span>
<span class="n">target_end</span><span class="p">()</span>

<span class="c1">-- 全局设置</span>
<span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">is_arch</span><span class="p">(</span><span class="s2">"arm64"</span><span class="p">,</span> <span class="s2">"armv7"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"ARM"</span><span class="p">)</span>
<span class="k">end</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test2"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST2"</span><span class="p">)</span>
<span class="n">target_end</span><span class="p">()</span>
</code></pre>
</div>

<h3 id="添加编译选项">添加编译选项</h3>

<p>如果有些编译选项，xmake没有提供内置api设置，那么我们可以退化到<code class="highlighter-rouge">add_cflags</code>, <code class="highlighter-rouge">add_cxflags</code>, <code class="highlighter-rouge">add_cxxflags</code>来设置，
不过这就需要用户自己去判断编译平台了，因为并不是所有编译flags每个平台都支持。</p>

<p>比如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cflags</span><span class="p">(</span><span class="s2">"-g"</span><span class="p">,</span> <span class="s2">"-O2"</span><span class="p">,</span> <span class="s2">"-DDEBUG"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"windows"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">add_cflags</span><span class="p">(</span><span class="s2">"/MT"</span><span class="p">)</span>
<span class="k">end</span>
</code></pre>
</div>

<p>所有选项值都基于gcc的定义为标准，如果其他编译器不兼容（例如：vc），xmake会自动内部将其转换成对应编译器支持的选项值。 
用户无需操心其兼容性，如果其他编译器没有对应的匹配值，那么xmake会自动忽略器设置。</p>

<p>我们也可以通过force参数来强制禁用flags的自动检测，直接传入编译器，哪怕编译器有可能不支持，也会设置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_cflags</span><span class="p">(</span><span class="s2">"-g"</span><span class="p">,</span> <span class="s2">"-O2"</span><span class="p">,</span> <span class="p">{</span><span class="n">force</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
</code></pre>
</div>

<p>那如何知道，哪些flags检测失败给忽略了呢，带<code class="highlighter-rouge">-v</code>编译就可以看到，比如：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake -v
checking <span class="k">for </span>the /usr/bin/xcrun -sdk macosx clang ... ok
checking <span class="k">for </span>the flags <span class="o">(</span>-Oz<span class="o">)</span> ... ok
checking <span class="k">for </span>the flags <span class="o">(</span>-Wno-error<span class="o">=</span>deprecated-declarations<span class="o">)</span> ... ok
checking <span class="k">for </span>the flags <span class="o">(</span>-fno-strict-aliasing<span class="o">)</span> ... ok
checking <span class="k">for </span>the flags <span class="o">(</span>-Wno-error<span class="o">=</span>expansion-to-defined<span class="o">)</span> ... no
</code></pre>
</div>

<p>最后备注下这三个api的区别：</p>

<ul>
  <li><code class="highlighter-rouge">add_cflags</code>：仅添加C代码相关编译flags</li>
  <li><code class="highlighter-rouge">add_cxflags</code>：添加C/C++代码相关编译flags</li>
  <li><code class="highlighter-rouge">add_cxxflags</code>：仅添加C++代码相关编译flags</li>
</ul>

<h3 id="添加库相关设置">添加库相关设置</h3>

<p>一个C/C++库的集成使用，通常需要设置头文件搜索目录，链接库名，库搜索目录，比如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_links</span><span class="p">(</span><span class="s2">"pthread"</span><span class="p">)</span>
    <span class="n">add_includedirs</span><span class="p">(</span><span class="s2">"/usr/local/include"</span><span class="p">)</span>
    <span class="n">add_linkdirs</span><span class="p">(</span><span class="s2">"/usr/local/lib"</span><span class="p">)</span>
</code></pre>
</div>

<p>通常，为了保证链接库的依赖顺序，系统库链接通常都会比较靠后，我们通过<code class="highlighter-rouge">add_syslinks()</code>来专门设置系统库链接，而<code class="highlighter-rouge">add_links()</code>通常用于非系统库链接：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_links</span><span class="p">(</span><span class="s2">"A"</span><span class="p">,</span> <span class="s2">"B"</span><span class="p">)</span>
    <span class="n">add_syslinks</span><span class="p">(</span><span class="s2">"pthread"</span><span class="p">)</span>
</code></pre>
</div>

<p>上面的配置，我们添加了两个第三方链接库：A, B，以及系统库pthread，整个完整的链接顺序是：<code class="highlighter-rouge">-lA -lB -lpthread</code>，syslinks会放在最后面。</p>

<p>如果你不确定实际的链接顺序，我们可以执行<code class="highlighter-rouge">xmake -v</code>编译，查看完整的链接参数命令行。</p>

<h3 id="设置语言标准">设置语言标准</h3>

<p>c标准和c++标准可同时进行设置，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- 设置c代码标准：c99， c++代码标准：c++11</span>
<span class="n">set_languages</span><span class="p">(</span><span class="s2">"c99"</span><span class="p">,</span> <span class="s2">"c++11"</span><span class="p">)</span>
</code></pre>
</div>

<p>注：并不是设置了指定的标准，编译器就一定会按这个标准来编译，毕竟每个编译器支持的力度不一样，但是xmake会尽最大可能的去适配当前编译工具的支持标准。</p>

<p>例如：windows下vs的编译器并不支持按c99的标准来编译c代码，只能支持到c89，但是xmake为了尽可能的支持它，所以在设置c99的标准后，
xmake会强制按c++代码模式去编译c代码，从一定程度上解决了windows下编译c99的c代码问题。</p>

<h3 id="设置编译优化">设置编译优化</h3>

<p>xmake提供了几种内置的编译优化配置：none, fast, faster, fastest, smallest, aggressive，来实现各种级别的编译优化。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">set_optimize</span><span class="p">(</span><span class="s2">"fastest"</span><span class="p">)</span>
</code></pre>
</div>

<p>如果用户通过flags来设置，还需额外考虑不同编译器的不同编译选项，xmake对其进行了内部映射处理，极大程度方便用户提供跨平台性。</p>

<p>如果想查看详细的映射规则，可以到xmake的官方文档进行查看：<a href="https://xmake.io/#/zh-cn/manual/project_target?id=targetset_optimize">编译优化设置</a></p>

<h3 id="调试和发布模式">调试和发布模式</h3>

<p>即使xmake提供了<code class="highlighter-rouge">set_optimize</code>简化了不同编译器的复杂配置，但是对于不同的编译模式: debug/release，还是要自己做一些繁琐的判断和配置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"debug"</span><span class="p">)</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"none"</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"release"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_symbols</span><span class="p">(</span><span class="s2">"hidden"</span><span class="p">)</span>
    <span class="n">set_strip</span><span class="p">(</span><span class="s2">"all"</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"iphoneos"</span><span class="p">,</span> <span class="s2">"android"</span><span class="p">)</span> <span class="k">then</span>
        <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"smallest"</span><span class="p">)</span>
    <span class="k">else</span>
        <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"fastest"</span><span class="p">)</span>
    <span class="k">end</span>
<span class="k">end</span>
</code></pre>
</div>

<p>这些看似常用的设置，如果每个项目都来一遍，那也很繁琐了，导致xmake.lua不够精简可读，因此xmake提供了一些常用内置规则来简化设置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.release"</span><span class="p">,</span> <span class="s2">"mode.debug"</span><span class="p">)</span>
</code></pre>
</div>

<p>只需这一行即可，效果是完全一致，用户还可以基于此在做一些额外的定制化配置来改写：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_rules</span><span class="p">(</span><span class="s2">"mode.release"</span><span class="p">,</span> <span class="s2">"mode.debug"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">is_mode</span><span class="p">(</span><span class="s2">"release"</span><span class="p">)</span> <span class="k">then</span>
    <span class="n">set_optimize</span><span class="p">(</span><span class="s2">"fastest"</span><span class="p">)</span>
<span class="k">end</span>
</code></pre>
</div>

<p>比如我想在release模式下，强制启用fastest编译优化，既然有了模式配置，那我们怎么切换到debug模式编译呢？（默认是release编译）</p>

<p>答案：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">xmake</span> <span class="n">f</span> <span class="o">-</span><span class="n">m</span> <span class="n">debug</span><span class="p">;</span>
<span class="n">xmake</span>
</code></pre>
</div>

<h3 id="添加源文件">添加源文件</h3>

<p>最后，我们在介绍下xmake最常用，也最为强大的设置之一，也就是对编译源文件的配置管理：<code class="highlighter-rouge">add_files()</code>。</p>

<p>我们可以用这个接口，添加各类xmake支持的源文件，比如：c/c++, asm, objc, swift, go, dlang等源文件，甚至是：<code class="highlighter-rouge">.obj</code>, <code class="highlighter-rouge">.a/.lib</code>等二进制对象和库文件。</p>

<p>例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_files</span><span class="p">(</span><span class="s2">"src/test_*.c"</span><span class="p">)</span>
<span class="n">add_files</span><span class="p">(</span><span class="s2">"src/xxx/**.cpp"</span><span class="p">)</span>
<span class="n">add_files</span><span class="p">(</span><span class="s2">"src/asm/*.S"</span><span class="p">,</span> <span class="s2">"src/objc/**/hello.m"</span><span class="p">)</span>
</code></pre>
</div>

<p>其中通配符<code class="highlighter-rouge">*</code>表示匹配当前目录下文件，而<code class="highlighter-rouge">**</code>则匹配多级目录下的文件。</p>

<p><code class="highlighter-rouge">add_files</code>的使用其实是相当灵活方便的，其匹配模式借鉴了premake的风格，但是又对其进行了改善和增强。</p>

<p>使得不仅可以匹配文件，还有可以在添加文件同时，过滤排除指定模式的一批文件。</p>

<p>例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="c1">-- 递归添加src下的所有c文件，但是不包括src/impl/下的所有c文件</span>
<span class="n">add_files</span><span class="p">(</span><span class="s2">"src/**.c|impl/*.c"</span><span class="p">)</span>

<span class="c1">-- 添加src下的所有cpp文件，但是不包括src/test.cpp、src/hello.cpp以及src下所有带xx_前缀的cpp文件</span>
<span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.cpp|test.cpp|hello.cpp|xx_*.cpp"</span><span class="p">)</span>
</code></pre>
</div>

<p>其中分隔符<code class="highlighter-rouge">|</code>之后的都是需要排除的文件，这些文件也同样支持匹配模式，并且可以同时添加多个过滤模式，只要中间用<code class="highlighter-rouge">|</code>分割就行了。。</p>

<p>添加文件的时候支持过滤一些文件的一个好处就是，可以为后续根据不同开关逻辑添加文件提供基础。</p>

<p>注：为了使得描述上更加的精简，<code class="highlighter-rouge">|</code>之后的过滤描述都是基于起一个模式：<code class="highlighter-rouge">src/*.cpp</code> 中<code class="highlighter-rouge">*</code>之前的目录为基础的。
所以上面的例子后面过滤的都是在src下的文件，这个是要注意的。</p>

<p>2.1.6版本之后，对<code class="highlighter-rouge">add_files</code>进行了改进，支持基于files更细粒度的编译选项控制，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_defines</span><span class="p">(</span><span class="s2">"TEST1"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"test/*.c"</span><span class="p">,</span> <span class="s2">"test2/test2.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">defines</span> <span class="o">=</span> <span class="s2">"TEST2"</span><span class="p">,</span> <span class="n">languages</span> <span class="o">=</span> <span class="s2">"c99"</span><span class="p">,</span> <span class="n">includedirs</span> <span class="o">=</span> <span class="s2">"."</span><span class="p">,</span> <span class="n">cflags</span> <span class="o">=</span> <span class="s2">"-O0"</span><span class="p">})</span>
</code></pre>
</div>

<p>可以在<code class="highlighter-rouge">add_files</code>的最后一个参数，传入一个配置table，去控制指定files的编译选项，里面的配置参数跟target的一致，并且这些文件还会继承target的通用配置<code class="highlighter-rouge">-DTEST1</code>。</p>

<p>2.1.9版本之后，支持添加未知的代码文件，通过设置rule自定义规则，实现这些文件的自定义构建，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="c1">-- ...</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/test/*.md"</span><span class="p">,</span> <span class="p">{</span><span class="n">rule</span> <span class="o">=</span> <span class="s2">"markdown"</span><span class="p">})</span>
</code></pre>
</div>

<p>并且在2.1.9版本之后，可以通过force参数来强制禁用cxflags,cflags等编译选项的自动检测，直接传入编译器，哪怕编译器有可能不支持，也会设置：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">,</span> <span class="p">{</span><span class="n">force</span> <span class="o">=</span> <span class="p">{</span><span class="n">cxflags</span> <span class="o">=</span> <span class="s2">"-DTEST"</span><span class="p">,</span> <span class="n">mflags</span> <span class="o">=</span> <span class="s2">"-framework xxx"</span><span class="p">}})</span>
</code></pre>
</div>

<h3 id="删除指定源文件">删除指定源文件</h3>

<p>既然讲到了添加源文件，那么如何删除，我们也顺带着讲下吧，我们只需要通过<code class="highlighter-rouge">del_files()</code>接口，就可以从前面<code class="highlighter-rouge">add_files</code>接口添加的文件列表中，删除指定的文件，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">del_files</span><span class="p">(</span><span class="s2">"src/test.c"</span><span class="p">)</span>
</code></pre>
</div>

<p>上面的例子，可以从<code class="highlighter-rouge">src</code>目录下添加除<code class="highlighter-rouge">test.c</code>以外的所有文件，当然这个也可以通过<code class="highlighter-rouge">add_files("src/*.c|test.c")</code>来达到相同的目的，但是这种方式更加灵活。</p>

<p>例如，我们可以条件判断来控制删除哪些文件，并且此接口也支持<code class="highlighter-rouge">add_files</code>的匹配模式，过滤模式，进行批量移除。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/**.c"</span><span class="p">)</span>
    <span class="n">del_files</span><span class="p">(</span><span class="s2">"src/test*.c"</span><span class="p">)</span>
    <span class="n">del_files</span><span class="p">(</span><span class="s2">"src/subdir/*.c|xxx.c"</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_plat</span><span class="p">(</span><span class="s2">"iphoneos"</span><span class="p">)</span> <span class="k">then</span>
        <span class="n">add_files</span><span class="p">(</span><span class="s2">"xxx.m"</span><span class="p">)</span>
    <span class="k">end</span>
</code></pre>
</div>

<p>通过上面的例子，我们可以看出<code class="highlighter-rouge">add_files</code>和<code class="highlighter-rouge">del_files</code>是根据调用顺序，进行顺序添加和删除的，并且通过<code class="highlighter-rouge">del_files("src/subdir/*.c|xxx.c")</code>删除一批文件，
并且排除<code class="highlighter-rouge">src/subdir/xxx.c</code>（就是说，不删除这个文件）。</p>

        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
                    
                    <h2 id="english">English</h2>
                    <ul>
                    
                    <li class="relatedPost">
                        <a href="/2019/11/10/quickstart-4-basic-project-settings/">Xmake Getting Started Tutorial 4: C/C++ project description settings
                        
                        </a>
                    </li>
                    
                    
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        
            </ul>
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
            
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2019/11/09/quickstart-3-run-and-debug/">xmake从入门到精通3：运行和调试目标程序</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2019/11/15/quickstart-5-build-android/">xmake从入门到精通5：Android平台编译详解</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
